package com.chenglu.android.classify.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.classify.bean.ClassisyTreeBean;
import com.chenglu.android.common.utils.LogUtils;


import java.util.List;

/**
 * @author: lyj
 * @Created: by Copyright 2023 3 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：分类选项2
 */
public class ClassifyTwoAdapter extends BaseQuickAdapter<ClassisyTreeBean.Data.ChildrenX, BaseViewHolder> {

    Context context;
//    List<HomeLike.Data.Records> data;
    public ClassifyTwoAdapter(Context context, @Nullable List<ClassisyTreeBean.Data.ChildrenX> data) {
        super(R.layout.item_classify_two, data);
        this.context = context;

    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, ClassisyTreeBean.Data.ChildrenX item) {

        if (item != null) {
//            LogUtils.v("searchadapter---" + item);

            TextView tvClassifyTwo = helper.getView(R.id.tv_classify_two);

            tvClassifyTwo.setText(item.getTitle());

//            LogUtils.d("图片和文字2222222"+ item.getTitle() + " 图片地址2222222" + item.getContent());

            RecyclerView rv = helper.getView(R.id.rv_classify_itemtwo);

            ClassifyThreeAdapter classifyThreeAdapter = new ClassifyThreeAdapter(context, item.getChildren());
            //
            rv.setLayoutManager(new GridLayoutManager(context, 3, LinearLayoutManager.VERTICAL, false));

            rv.setAdapter(classifyThreeAdapter);
            classifyThreeAdapter.notifyDataSetChanged();

            classifyThreeAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                    if (item.getChildren() != null) {
//                        LogUtils.d("indexPic--", item.getChildren() .toString());
//
//                        if (item.getChildren().get(position).getTitle().equals("产品区")) {
//                            Intent intent = new Intent(context, ProductAreaActivity.class);
//                            intent.putExtra("categoryId", item.getChildren() .get(position).getId());
//                            intent.putExtra("categoryName", item.getChildren().get(position).getTitle());
//                            context.startActivity(intent);
//                        } else if (item.getChildren().get(position).getTitle().equals("批发区")) {
//                            Intent intent = new Intent(context, WholesaleActivity.class);
//                            intent.putExtra("categoryId", item.getChildren() .get(position).getId());
//                            intent.putExtra("categoryName", item.getChildren().get(position).getTitle());
//                            context.startActivity(intent);
//                        } else if (item.getChildren().get(position).getTitle().equals("红宝区")) {
//                            Intent intent = new Intent(context, RubyActivity.class);
//                            intent.putExtra("categoryId", item.getChildren() .get(position).getId());
//                            intent.putExtra("categoryName", item.getChildren().get(position).getTitle());
//                            context.startActivity(intent);
//                        } else {
//                            Intent intent = new Intent(context, SearchActivity.class);
//                            intent.putExtra("categoryName", item.getChildren().get(position).getTitle());
//                            intent.putExtra("categoryId", item.getChildren() .get(position).getId());
//                            context.startActivity(intent);
//                        }
//
//                    }
                }

            });

        }


    }
}
